﻿using log4net;
using Quartz;

namespace TdxApiPool.Task
{
    [DisallowConcurrentExecution]
    public class ProtectionTask : IJob
    {

        private static readonly ILog Log = LogManager.GetLogger(typeof(ProtectionTask));
        public void Execute(IJobExecutionContext context)
        {
            Reconnect();
        }

        private void Reconnect()
        {
            Log.Info("------------------------------");
            Log.Info("start ProtectionTask.Reconnect");
            
            //获取发生错误的行情轮训器
            var errorHqLoopers = SanpshootService.GetService().ErrorHqLoopers;
            
            foreach (var errorHqLooper in errorHqLoopers)
            {
                var tdxConnection = errorHqLooper.TdxConnection;
                var reconected = tdxConnection.Connected;
                Log.Info(
                    $"name = {tdxConnection.ConnectionName}\nip = {tdxConnection.Ip}:{tdxConnection.Port}\nreconnect = {reconected}\n");
                if (reconected)
                {
                    errorHqLooper.Start();
                    continue;
                }
            }
            Log.Info("end ReConnectTask.Reconnect");
            Log.Info("------------------------------");
        }
    }
}